home *** CD-ROM | disk | FTP | other *** search
- Path: fang.dsto.defence.gov.au!usenet
- From: IainJameson <Iain.Jameson@dsto.defence.gov.au>
- Newsgroups: comp.lang.c++
- Subject: Opening, closing then opening files.
- Date: Wed, 10 Apr 1996 12:38:03 +0930
- Organization: DSTO,Australia
- Message-ID: <316B2613.1A5@dsto.defence.gov.au>
- NNTP-Posting-Host: fang.dsto.defence.gov.au
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.01 (X11; I; HP-UX A.09.01 9000/735)
-
- Hi
-
- I have a small problem.
-
- I have the following C++ code :
-
- ifstream inFile;
- char *file_name;
-
- void do_stuff(...)
- {
- ...
- ...
-
- inFile.open(file_name,ios::in);
-
- ...
- ...
- }
-
- I open file_name, read the contents and do stuff.
- Then I want to open a different file_name
- using this same piece of code. Unfortunately I can't.
-
- I know that I should change inFile to be a pointer to ifstream and use
- delete and new, but
-
- 1 : I want to change as little code as possible, and
- 2 : I did this and got an `illegal instruction' error when I tried to
- run
- run the programme. I have no idea why.
-
- So the question is, how do I keep the original code and open a different
- file_name? Can it be done without changing the original code too much?
- Or do I have to make inFile a pointer to ifstream? If I do, how do I get
- rid of the illegal instruction error?
-
- Suggestions would be appreciated.
-
- Iain Jameson.
-